package dian.qing.li.demo.security.config.bean;

import dian.qing.li.demo.security.utils.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

/**
 * @program: pactera
 * @description:
 * @author: EC_liqingdian
 * @create: 2020-02-26 17:09
 **/
@Slf4j
public class TaskDisposable implements DisposableBean {

    @Override
    public void destroy() throws Exception {
        // 销毁
        log.info("关闭线程");
        // 关闭线程或线程池
        ThreadPoolTaskScheduler scheduler = SpringUtils.getBean("scheduler", ThreadPoolTaskScheduler.class);
        scheduler.shutdown();
        ThreadPoolTaskExecutor executor = SpringUtils.getBean("executor", ThreadPoolTaskExecutor.class);
        executor.shutdown();
    }
}
